package com.fenghongzhang.day008;

import androidx.appcompat.app.AppCompatActivity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void write(View view) {

        /**
         * 1,文件名
         * 2,文件的访问方式,private
         */
        SharedPreferences one = getSharedPreferences("one", MODE_PRIVATE);
        SharedPreferences.Editor edit = one.edit();
        edit.putString("name","小明");
        edit.putBoolean("isOpen",true);
        edit.putInt("age",16);
        edit.putLong("bigAge",1000l);
        edit.putFloat("price",1.0f);
        edit.commit();



    }

    public void read(View view) {
        SharedPreferences one = getSharedPreferences("one", MODE_PRIVATE);
        boolean isOpen = one.getBoolean("isOpn",false);
        String string = one.getString("name", "大明");
        int age = one.getInt("age", 18);
        long bigAge = one.getLong("bigAge", 2000);
        float price = one.getFloat("price", 123.4f);
        Toast.makeText(this, isOpen+string+age+bigAge+price, Toast.LENGTH_SHORT).show();
    }

    public void rm(View view) {
        SharedPreferences one = getSharedPreferences("one", MODE_PRIVATE);
        SharedPreferences.Editor edit = one.edit();
//        edit.remove("age");
        edit.clear();
        edit.commit();
    }
}
